package com.coflxl.web.config;

import javax.sql.DataSource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DynamicDataSourceRegister {
    private static final Map<String, DataSource> DATA_SOURCE_MAP = new ConcurrentHashMap<>();
    private static final Map<String, String> DIALECT_MAP = new ConcurrentHashMap<>();

    public static void addDataSource(String name, DataSource ds, String dialect) {
        DATA_SOURCE_MAP.put(name, ds);
        DIALECT_MAP.put(name, dialect);
    }

    public static DataSource getDataSource(String name) {
        return DATA_SOURCE_MAP.get(name);
    }

    public static String getDialect(String name) {
        return DIALECT_MAP.getOrDefault(name, "mysql");
    }
}
